package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.SettingsPane;
import com.gluonhq.charm.glisten.control.settings.Option;
import com.gluonhq.charm.glisten.control.settings.OptionEditor;
import javafx.util.Callback;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.control.ControlActions;
import xworker.javafx.util.JavaFXUtils;

public class SettingsPaneActions {
    static{
        PropertyFactory.regist(SettingsPane.class, "titleFilter", o -> {
            SettingsPane obj = (SettingsPane) o;
            return obj.titleFilter();
        });
    }

    public static void init(SettingsPane node, Thing thing, ActionContext actionContext) {
        ControlActions.init(node, thing, actionContext);

        if(thing.valueExists("searchBoxVisible")){
            node.setSearchBoxVisible(thing.getBoolean("searchBoxVisible"));
        }

        Callback<Option, OptionEditor<?>> optionEditorFactory = JavaFXUtils.getObject(thing, "optionEditorFactory", actionContext);
        if(optionEditorFactory != null){
            node.setOptionEditorFactory(optionEditorFactory);
        }
        //Unknown type: Callback<Option,OptionEditor<?>>
        String titleFilter = JavaFXUtils.getObject(thing, "titleFilter", actionContext);
        if (titleFilter != null) {
            node.setTitleFilter(titleFilter);
        }

    }

    public static SettingsPane create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");
        SettingsPane node = new SettingsPane();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }

}